#include <stdio.h>
#include <limits.h>

const char* daysofweek[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int daysofmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int daysofmonthLeap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool isLeap(int year)
{
	return year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
}

int getYear(int& days)
{
	int year = 2000;

	int daysin400years = 365 * 400 + 100 - 4 + 1;
	year += days / daysin400years * 400;
	days %= daysin400years;

	if (days >= 366)
	{
		year++;
		days -= 366;
	}

	int daysin100years = 365 * 100 + 25 - 1;
	year += days / daysin100years * 100;
	days %= daysin100years;

	int daysin4years = 365 * 4 + 1;
	year += days / daysin4years * 4;
	days %= daysin4years;

	while (1)
	{
		if (isLeap(year))
		{
			if (days >= 366)
				days -= 366;
			else
				break;
		}
		else
		{
			if (days >= 365)
				days -= 365;
			else
				break;
		}
		year++;
	}
	return year;
}

int getYear2(int& days)
{
	int year = 2000;

	int daysin400years = 365 * 400 + 100 - 4 + 1;
	year += days / daysin400years * 400;
	days %= daysin400years;

	while (1)
	{
		if (isLeap(year))
		{
			if (days >= 366)
				days -= 366;
			else
				break;
		}
		else
		{
			if (days >= 365)
				days -= 365;
			else
				break;
		}
		year++;
	}

	return year;
}

int getMonth(int year, int& days)
{
	int m;
	for (m = 0; m < 12; m++)
	{
		if (isLeap(year))
		{
			if (days >= daysofmonthLeap[m])
				days -= daysofmonthLeap[m];
			else
				break;
		}
		else
		{
			if (days >= daysofmonth[m])
				days -= daysofmonth[m];
			else
				break;
		}
	}
	return m;
}

int main()
{
	while (1)
	{
		int days;
		scanf("%d", &days);
		if (days == -1)
			break;

		int dayofweek = (6 + days) % 7;
		int year = getYear(days);
		int month = getMonth(year, days);
		printf("%d-%02d-%02d %s\n", year, month + 1, days + 1, daysofweek[dayofweek]);
	}
	return 0;
}